/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package businessDelegates;

import businessObjects.Formulario;
import java.util.List;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import sessionFacades.FormularioFacadeRemote;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author williamprado
 */
@EJB(name="formulariofr", beanInterface = FormularioFacadeRemote.class)
public class FormularioBusinessDelegate {

    public FormularioBusinessDelegate(){

    }

    public void guardarFormulario(Formulario form){
       try {
            Context ctx = new InitialContext();
            FormularioFacadeRemote formularioFacadeBean = (FormularioFacadeRemote) ctx.lookup("java:comp/env/formulariofr");
            formularioFacadeBean.guardarFormulario(form);
        } catch (NamingException ex) {
            Logger.getLogger(ClienteBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

   public void actualizarFormulario(Formulario form){
        try {
            Context ctx = new InitialContext();
            FormularioFacadeRemote formularioFacadeBean = (FormularioFacadeRemote) ctx.lookup("java:comp/env/formulariofr");
            formularioFacadeBean.actualizarFormulario(form);
        } catch (NamingException ex) {
            Logger.getLogger(FormularioBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void eliminarFormulario(int id){
        try {
            Context ctx = new InitialContext();
            FormularioFacadeRemote formularioFacadeBean = (FormularioFacadeRemote) ctx.lookup("java:comp/env/formulariofr");
            formularioFacadeBean.eliminarFormulario(id);
        } catch (NamingException ex) {
            Logger.getLogger(FormularioBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Formulario consultarFormulario(int id){
          try {
            Formulario f = new Formulario();
            Context ctx = new InitialContext();
            FormularioFacadeRemote formularioFacadeBean = (FormularioFacadeRemote) ctx.lookup("java:comp/env/formulariofr");
            f = formularioFacadeBean.consultarFormulario(id);
            return f;
        } catch (NamingException ex) {
            Logger.getLogger(ClienteBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }        
    }

    public List<Formulario> consultarFormulariosPauta(int idPauta){
          try {
            List<Formulario> lf;
            Context ctx = new InitialContext();
            FormularioFacadeRemote formularioFacadeBean = (FormularioFacadeRemote) ctx.lookup("java:comp/env/formulariofr");
            lf = formularioFacadeBean.consultarFormulariosPauta(idPauta);
            return lf;
        } catch (NamingException ex) {
            Logger.getLogger(ClienteBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }        
    }
}
